import requests
import pytest
import random
# Url="http://123.56.16.34:8899"
# response =requests.post(url=Url+"/adminapi/login",json={"account":"admin","pwd":"123456","imgcode":"a"})
# # print(response.json())
# # print(type(response.json()))
# token = response.json()['data']['token']
# print(token)
# assert response.status_code == 200
# assert response.json()['msg'] == 'ok'
# res = requests.post(url =Url+"/adminapi/user/user_group/save.html",
#                          headers={"Authori-Zation":"Bearer"+ str(token)},
#                          json={"group_name":str(random.randint(0,99999))+"门马one"})
# print(res.json())
#1.1新增用户分组
# res = requests.post(Url+"/adminapi/user/user_group/save.html",headers={"Authori-Zation":"Bearer "+str(token)},json={"group_name":str(random.randint(0,99999))+"门马2号"})
# print(res.json())
# assert res.json()['msg'] == '提交成功！'
# assert res.status_code == 200
#request
#1.2删除用户分组
# res = requests.delete(Url+"/adminapi/user/user_group/del"+"/262",headers={"Authori-Zation":"Bearer "+str(token)})
# print(res.json())
# assert res.json()['msg'] == '删除成功!'
# assert res.status_code == 200
#2.1添加客服话术
# res1 =requests.post(Url+"/adminapi/app/wechat/speechcraft",headers={"Authori-Zation":"Bearer "+str(token)},json={"cate_id":0,"title":"刘门马话术讨论","message":"撒大苏打实打实的","sort":0})
# print(res1.json())
# assert res1.json()['msg'] == '创建话术成功'
# assert res1.status_code == 200
#2.2删除刚新增的客服话术
# res1 = requests.delete(Url+"/adminapi/app/wechat/speechcraft"+"/2049",headers={"Authori-Zation":"Bearer "+str(token)})
# print(res1.json())
# assert res1.json()['msg'] =='删除成功'
# assert res1.status_code == 200
#3.1添加用户标签
# res2 =requests.post(Url+"/adminapi/user/user_label/save.html",headers={"Authori-Zation":"Bearer "+str(token)},json={"label_cate":96,"label_name":"门马"})
# print(res2.json())
# assert res2.json()['msg'] == '保存成功'
# assert res2.status_code == 200
#3.2删除用户标签
# res2 = requests.delete(Url+"/adminapi/user/user_label/del"+"/173",headers={"Authori-Zation":"Bearer "+str(token)})
# print(res2.json())
# assert res2.json()['msg'] =='删除成功'
# assert res2.status_code == 200
# 作业：
# 1、添加用户分组——》删除刚新增的用户分组
# 2、添加客服话术——》删除刚新增的客服话术
# 3、添加用户标签——》删除刚新增的用户标签
# 使用requests+pytest实现，每条用例要加上断言，对于新增的数据，要做关联
# class CRMEB():
#     @pytest.fixture(scope='function')
#     def Login(self):
#         self.url = "http://123.56.16.34:8899"
#         response = requests.post(url=Url + "/adminapi/login",
#                                  json={"account": "admin", "pwd": "123456", "imgcode": "a"})
#         token = response.json()['data']['token']
#     def add_group(self,Login):
#         res = requests.post(Url + "/adminapi/user/user_group/save.html",
#                             headers={"Authori-Zation": "Bearer " + str(token)},
#                             json={"group_name": str(random.randint(0, 99999)) + "门马2号"})
#         print(res.json())
#         assert res.json()['msg'] == '提交成功！'
#         assert res.status_code == 200
#     def delete_group(self,Login):
#         res = requests.delete(Url+"/adminapi/user/user_group/del"+"/262",headers={"Authori-Zation":"Bearer "+str(token)})
#         print(res.json())
#         assert res.json()['msg'] == '删除成功!'
#         assert res.status_code == 200
#     def add_script(self):
#         res1 =requests.post(Url+"/adminapi/app/wechat/speechcraft",headers={"Authori-Zation":"Bearer "+str(token)},json={"cate_id":0,"title":"刘门马话术讨论","message":"撒大苏打实打实的","sort":0})
#         print(res1.json())
#         assert res1.json()['msg'] == '创建话术成功'
#         assert res1.status_code == 200
#     def delete_script(self,Login):
#         res1 = requests.delete(Url+"/adminapi/app/wechat/speechcraft"+"/2049",headers={"Authori-Zation":"Bearer "+str(token)})
#         print(res1.json())
#         assert res1.json()['msg'] =='删除成功'
#         assert res1.status_code == 200
#     def add_label(self,Login):
#         res2 =requests.post(Url+"/adminapi/user/user_label/save.html",headers={"Authori-Zation":"Bearer "+str(token)},json={"label_cate":96,"label_name":"门马"})
#         print(res2.json())
#         assert res2.json()['msg'] == '保存成功'
#         assert res2.status_code == 200
#     def delete_label(self,Login):
#         res2 = requests.delete(Url+"/adminapi/user/user_label/del"+"/173",headers={"Authori-Zation":"Bearer "+str(token)})
#         print(res2.json())
#         assert res2.json()['msg'] =='删除成功'
#         assert res2.status_code == 200
# if __name__ == '__main__':
#     pytest.main()
